import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class RevenueEntry implements Comparable<RevenueEntry> {

    private String id;
    private LocalDate date;
    private LocalTime begin;
    private LocalTime end;
    private boolean isPenalty;
    private int income;

    public RevenueEntry(CustomerAction ca, boolean flag, int money) {
        this.id = ca.getUserId();
        this.date = ca.getBookDate();
        this.begin = ca.getBeginTime();
        this.end = ca.getEndTime();
        this.isPenalty = flag;
        this.income = money;
    }

    public String getId() {
        return id;
    }

    public LocalDate getDate() {
        return date;
    }

    public LocalTime getBegin() {
        return begin;
    }

    public LocalTime getEnd() {
        return end;
    }

    public boolean isPenalt() {
        return isPenalty;
    }

    public int getIncome() {
        return income;
    }

    public boolean infoEqual(CustomerAction ca) {
        if (this.isPenalt())
            return false;

        if (!this.id.equals(ca.getUserId()))
            return false;

        if (!this.date.equals(ca.getBookDate()))
            return false;

        if (!this.begin.equals(ca.getBeginTime()))
            return false;

        if (!this.end.equals(ca.getEndTime()))
            return false;

        return true;
    }

    @Override
    public String toString() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
        String str = "> ";
        String date = this.date.toString() + " ";
        String timestr = this.begin.format(formatter) + "~" + this.end.format(formatter) + " ";
        String info = this.isPenalty ? "违约金 " : "";
        String val = "" + this.income;
        str = str + date + timestr + info + val;
        return str;
    }

    @Override
    public int compareTo(RevenueEntry o) {
        if (this.begin.isAfter(o.begin))
            return 1;
        if (this.begin.equals(o.begin)) {
            if (this.end.isAfter(o.end))
                return 1;
            if (this.end.equals(o.end))
                return 0;
        }
        return -1;
    }
}
